package com.zykj.jdkobserver;

import com.zykj.observer.DisplayElement;

import java.util.Observable;
import java.util.Observer;

/**
 * @author zhoulj(周利军) [1217102780@qq.com]
 * @Title: GenerateDisplay
 * @Project: ${MODEL_NAME}
 * @Module ID:   <(模块)类编号，可以引用系统设计中的类编号>
 * @Comments: <对此类的描述，可以引用系统设计中的描述>
 * @JDK version used:      <JDK1.8> 10
 * @since 2018/12/26-14:10
 */
public class GenerateDisplay implements Observer, DisplayElement {
    float wendu, shidu;
    /**
     * This method is called whenever the observed object is changed. An
     * application calls an <tt>Observable</tt> object's
     * <code>notifyObservers</code> method to have all the object's
     * observers notified of the change.
     *
     * @param o   the observable object.
     * @param arg an argument passed to the <code>notifyObservers</code>
     */
    @Override
    public void update(Observable o, Object arg) {
        if (o instanceof WeatherData) {
            WeatherData weatherData = (WeatherData)o;
            this.wendu = weatherData.getWendu();
            this.shidu = weatherData.getShudu();
            display();
        }
    }

    @Override
    public void display() {
        System.out.println(String.format("通用布告栏：wendu:%s,shidu:%s",wendu,shidu));
    }
}
